import { Component } from 'react';
class Components extends Component {
    state = {
        title: '',    //评论人
        context: '',  //评论内容
    }
    // 获取input值
    upInput = (val) => {
        let title = val.target.value
        this.setState({
            title
        })
       
    }
    // 获取文本域的值
    upTextarea = (val) => {
        this.setState({
            context: val.target.value
        })
    }
    // 发表评论按钮
    btn = () => {
        const {title,context} = this.state
        this.props.updateList({title, context})
        this.setState({
            title: '',    
            context: '',
        })
    }
    render() {
        return (
            <>
                <div>
                    <div>
                        <input type="text" value={this.state.title} onChange={this.upInput} placeholder='请输入评论人' />
                    </div>
                    <div>
                        <textarea cols="30" rows="10" value={this.state.context} onChange={this.upTextarea} placeholder='请输入评论内容' ></textarea>
                    </div>
                    <button onClick={this.btn}>发表评论</button>
                </div>
            </>
        );
    }
}

export default Components;